package com.atguigu.gmall.index.service;

import com.atguigu.gmall.common.bean.ResponseVo;
import com.atguigu.gmall.index.annotation.GmallCache;
import com.atguigu.gmall.index.feign.GmallPmsClient;
import com.atguigu.gmall.pms.entity.CategoryEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Aupt
 * @create 2022-05-30-15:07
 */
@Service
public class IndexService {

    @Autowired
    private GmallPmsClient gmallPmsClient;

    public static final String KEY_PREFIX = "index:category:";
    public static final String LOCK_PREFIX = "index:category:lock:";

    public List<CategoryEntity> queryLevelOneCategories() {
        ResponseVo<List<CategoryEntity>> listResponseVo = this.gmallPmsClient.queryCategoryByParentId(0L);
        return listResponseVo.getData();
    }

    @GmallCache(prefix = KEY_PREFIX,timeout = 129600,random = 14400,lock = LOCK_PREFIX)
    public List<CategoryEntity> queryLevelTwoCategoriesWithSub(Long pid) {
        ResponseVo<List<CategoryEntity>> listResponseVo = this.gmallPmsClient.queryCategoriesWithSub(pid);
        return listResponseVo.getData();
    }
}
